package com.heaven.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heaven.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper extends BaseMapper {

    @Select("select * from user where username=#{username} and password=#{password}")
    User login(User user);

    @Insert("insert into user value (null,#{username}," +
            "#{password},#{phone},#{email},#{status},#{created},#{updated})")
    void addUser(User user);

    @Select("select * from user where username like \"%\"#{query}\"%\" limit #{startNum},#{size}")
    List<User> userList(@Param("query") String query,
                        @Param("startNum") Integer startNum,
                        @Param("size") Integer size);

    @Select("select count(1) from user where username like \"%\"#{query}\"%\"")
    Long userCount(String query);

    @Update("update user set status=#{status},updated=#{updated} where id=#{id}")
    void userStatus(User user);

    @Select("select id,username,phone,email from user where id=#{id}")
    User findUserId(Integer id);

    @Update("update user set phone=#{phone},email=#{email},password=#{newpassword},updated=#{updated} where id=#{id}")
    void updateUser(User user);

    @Select("select * from user where password=#{password} and username=#{username}")
    User auth(User user);

    @Delete("delete from user where id=#{id}")
    void deleteUser(Integer id);

    @Select("select password from user where id=#{id}")
    String selectPassword(Integer id);

    @Update("update user set phone=#{phone},email=#{email},updated=#{updated} where id=#{id}")
    void updatePasswordUser(User user);

    @Select("select count(1) from user where password=#{password} and username=#{username}")
    Integer authUser(User user);
}
